package Q2;

import java.util.*;

public class Main {

    public static List<List<Integer>> lists = new ArrayList<>();
    public static List<Integer> ret = new ArrayList<>();
    public static int n;
    public static int sum = Integer.MAX_VALUE;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        n = scanner.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = scanner.nextInt();
        }

        for (int i = 0; i < n; i++) {
            lists.add(new ArrayList<>(method(arr[i])));
        }

        dfs(0, 0);

        //在每个 list 中选出一个值
        System.out.println(sum == Integer.MAX_VALUE ? -1 : sum);

    }

    public static List<Integer> method(int num) {

        int temp = num;
        List<Integer> list = new ArrayList<>();

        int count = 2;
        while (temp > 0) {
            if (temp % count == 0) {
                temp /= count;
                list.add(count);
            } else {
                count++;
            }
        }

        Collections.sort(list);
        return list;
    }

    public static void dfs(int listIndex, int numIndex) {

        if (ret.size() == n) {
            int temp = 0;
            for (int i : ret) {
                temp += i;
            }
            sum = Math.min(sum, temp);
            return;
        }

        if (listIndex == n) {
            return;
        }

        List<Integer> list = lists.get(listIndex);

        if (numIndex < listIndex) {
            //选
            if (!ret.contains(list.get(numIndex))) {
                ret.add(list.get(numIndex));
                dfs(listIndex + 1, 0);
                //回溯
                ret.remove(ret.size() - 1);
            }

            //不选
            dfs(listIndex, numIndex + 1);
        }
    }
}
